package com.wework;

import me.chanjar.weixin.cp.api.WxCpAgentService;
import me.chanjar.weixin.cp.api.WxCpDepartmentService;
import me.chanjar.weixin.cp.api.WxCpExternalContactService;
import me.chanjar.weixin.cp.api.WxCpUserService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpAgent;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;

import java.util.List;

/**
 * @Author: tang
 * @Description:
 * @Date 2025/3/13 21:49
 */
public class CpWeWorkMain {

    public static void main(String[] args) throws Exception{

        WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
        config.setCorpId("wxc850c4399046bd6e");      // 设置微信企业号的appid
        config.setCorpSecret("yoEmPrTrpX9Jr9AikTgYBHM9OXG2j6VoU-lS0Yp0ug0");  // 设置微信企业号的app corpSecret
        config.setAgentId(1000);     // 设置微信企业号应用ID
        config.setToken("xjjk");       // 设置微信企业号应用的token
        config.setAesKey("OVCpnYKiMjbm6nwOmLbGqedPh3o3qxztEAPqrnw0Tr4");      // 设置微信企业号应用的EncodingAESKey

        WxCpServiceImpl wxCpService = new WxCpServiceImpl();
        wxCpService.setWxCpConfigStorage(config);

//        WxCpUserService userService = wxCpService.getUserService();
//        WxCpUser wxCpUser = userService.getById("74556");
//        System.out.println(wxCpUser);

        String url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list?userid=%s";

        String result = wxCpService.get(String.format(url, "74556"), null);
        System.out.println(result);

         wxCpService.getExternalContactService()
                .getContactDetail("wmLO4XBwAAdUlG3Rw6V7aK093vZbm6tg","CURSOR");

//        WxCpAgentService agentService = wxCpService.getAgentService();
//        List<WxCpAgent> list = agentService.list();
//        System.out.println(list);

//        WxCpDepartmentService departmentService = wxCpService.getDepartmentService();
//        List<WxCpDepart> wxCpDeparts = departmentService.simpleList(null);
//        System.out.println(wxCpDeparts);

//        WxCpUserService userService = wxCpService.getUserService();
//        List<WxCpUser> wxCpUsers = userService.listSimpleByDepartment(141L, false, 0);
//        System.out.println(wxCpUsers);

//        String userId = "74556";
//        WxCpMessage message = WxCpMessage.TEXT()
//                .agentId(1000060)
//                .toUser(userId)
//                .content("Hello World！")
//                .build();
//        wxCpService.getMessageService().send(message);
    }

}
